//
//  PriorityCell.m
//  WOPrototype
//
//  Created by Olof Millberg on 2010-04-23.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "PriorityCell.h"

@implementation PriorityCell
@synthesize priorityButton;
@synthesize priorities;
@synthesize priority;
@synthesize delegate;

- (void) setPriority:(NSString *)aPriority
{
	[priority release];
	priority = [aPriority retain];
	[self.priorityButton setTitle:priority forState:UIControlStateNormal];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
	if (buttonIndex != actionSheet.cancelButtonIndex)
	{
		[self.priorityButton setTitle:[actionSheet buttonTitleAtIndex:buttonIndex] forState:UIControlStateNormal];
		[delegate priorityChanged:self.priorityButton.currentTitle];
	}
	[actionSheet release];
}

- (void) showPriorityPicker
{
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Välj prioritet"
													  delegate:self
											 cancelButtonTitle:nil
										destructiveButtonTitle:nil
											 otherButtonTitles:nil];
	
	for (NSString *currentPriority in priorities)
		[actionSheet addButtonWithTitle:currentPriority];
	
	[actionSheet addButtonWithTitle:@"Tillbaka"];
	[actionSheet setCancelButtonIndex:priorities.count];
	[actionSheet showInView:self.window];
}

@end